﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using StripeOne.Core.S1Tools;
using System.Globalization;

namespace StripeOne.Core.S1Cache
{
    public static class S1Cache
    {
        private static CultureInfo _cInfo = new CultureInfo("en-US");
        public static void Add(object obj, string key, int seconds)
        {
            S1IISCache.Add(obj, key, seconds);
            S1AppCache.Add(obj, key, seconds);
        }
        public static void Remove(string key)
        {
            S1IISCache.Remove(key);
            S1AppCache.Remove(key);
        }
        public static object GetObject(string key)
        {
            int num;
            return S1Cache.GetObject(key, out num);
        }
        public static object GetObject(string key, out int remainingSeconds)
        {
            remainingSeconds = 0;
            object @object = S1IISCache.GetObject(key, out remainingSeconds);
            if (@object == null)
            {
                @object = S1AppCache.GetObject(key, out remainingSeconds);
                if (@object != null)
                {
                    S1IISCache.Add(@object, key, remainingSeconds);
                }
            }
            return @object;
        }
        public static TR AutoCache<TR>(string key, int time, Func<TR> retriever)
        {
            object @object = S1Cache.GetObject(key);
            if (@object != null && @object is TR)
            {
                return (TR)@object;
            }
            TR tR = retriever();
            S1Cache.Add(tR, key, time);
            return tR;
        }
        public static TR AutoCache<T1, TR>(string key, int time, Func<T1, TR> retriever, T1 param1)
        {
            object @object = S1Cache.GetObject(key);
            if (@object != null && @object is TR)
            {
                return (TR)@object;
            }
            TR tR = retriever(param1);
            S1Cache.Add(tR, key, time);
            return tR;
        }
        public static TR AutoCache<T1, T2, TR>(string key, int time, Func<T1, T2, TR> retriever, T1 param1, T2 param2)
        {
            object @object = S1Cache.GetObject(key);
            if (@object != null && @object is TR)
            {
                return (TR)@object;
            }
            TR tR = retriever(param1, param2);
            S1Cache.Add(tR, key, time);
            return tR;
        }
        public static TR AutoCache<T1, T2, T3, TR>(string key, int time, Func<T1, T2, T3, TR> retriever, T1 param1, T2 param2, T3 param3)
        {
            object @object = S1Cache.GetObject(key);
            if (@object != null && @object is TR)
            {
                return (TR)@object;
            }
            TR tR = retriever(param1, param2, param3);
            S1Cache.Add(tR, key, time);
            return tR;
        }
        public static TR AutoCache<T1, T2, T3, T4, TR>(string key, int time, Func<T1, T2, T3, T4, TR> retriever, T1 param1, T2 param2, T3 param3, T4 param4)
        {
            object @object = S1Cache.GetObject(key);
            if (@object != null && @object is TR)
            {
                return (TR)@object;
            }
            TR tR = retriever(param1, param2, param3, param4);
            S1Cache.Add(tR, key, time);
            return tR;
        }
        public static string GetString(string key)
        {
            return S1Cache.GetObject(key).ToString();
        }
        public static string GetString(string key, string defaultValue)
        {
            return S1Cache.GetObject(key).ToString(defaultValue);
        }
        public static byte GetByte(string key)
        {
            return S1Cache.GetObject(key).ToByte();
        }
        public static byte GetByte(string key, byte defaultValue)
        {
            return S1Cache.GetObject(key).ToByte(defaultValue);
        }
        public static short GetInt16(string key)
        {
            return S1Cache.GetObject(key).ToInt16();
        }
        public static short GetInt16(string key, short defaultValue)
        {
            return S1Cache.GetObject(key).ToInt16(defaultValue);
        }
        public static int GetInt32(string key)
        {
            return S1Cache.GetObject(key).ToInt32();
        }
        public static int GetInt32(string key, int defaultValue)
        {
            return S1Cache.GetObject(key).ToInt32(defaultValue);
        }
        public static long GetInt64(string key)
        {
            return S1Cache.GetObject(key).ToInt64();
        }
        public static long GetInt64(string key, long defaultValue)
        {
            return S1Cache.GetObject(key).ToInt64(defaultValue);
        }
        public static decimal GetDecimal(string key)
        {
            return S1Cache.GetObject(key).ToDecimal();
        }
        public static decimal GetDecimal(string key, decimal defaultValue)
        {
            return S1Cache.GetObject(key).ToDecimal(defaultValue);
        }
        public static decimal GetDecimal(string key, string cultureName)
        {
            return S1Cache.GetObject(key).ToDecimal(cultureName);
        }
        public static decimal GetDecimal(string key, string cultureName, decimal defaultValue)
        {
            return S1Cache.GetObject(key).ToDecimal(cultureName, defaultValue);
        }
        public static decimal GetDecimal(string key, CultureInfo cultureInfo)
        {
            return S1Cache.GetObject(key).ToDecimal(cultureInfo);
        }
        public static decimal GetDecimal(string key, CultureInfo cultureInfo, decimal defaultValue)
        {
            return S1Cache.GetObject(key).ToDecimal(cultureInfo, defaultValue);
        }
        public static float GetSingle(string key)
        {
            return S1Cache.GetObject(key).ToSingle();
        }
        public static float GetSingle(string key, float defaultValue)
        {
            return S1Cache.GetObject(key).ToSingle(defaultValue);
        }
        public static float GetSingle(string key, CultureInfo cultureInfo)
        {
            return S1Cache.GetObject(key).ToSingle(cultureInfo);
        }
        public static float GetSingle(string key, CultureInfo cultureInfo, float defaultValue)
        {
            return S1Cache.GetObject(key).ToSingle(cultureInfo, defaultValue);
        }
        public static float GetSingle(string key, string cultureName)
        {
            return S1Cache.GetObject(key).ToSingle(cultureName);
        }
        public static float GetSingle(string key, string cultureName, float defaultValue)
        {
            return S1Cache.GetObject(key).ToSingle(cultureName, defaultValue);
        }
        public static float GetFloat(string key)
        {
            return S1Cache.GetObject(key).ToFloat();
        }
        public static float GetFloat(string key, float defaultValue)
        {
            return S1Cache.GetObject(key).ToFloat(defaultValue);
        }
        public static float GetFloat(string key, CultureInfo cultureInfo)
        {
            return S1Cache.GetObject(key).ToFloat(cultureInfo);
        }
        public static float GetFloat(string key, CultureInfo cultureInfo, float defaultValue)
        {
            return S1Cache.GetObject(key).ToFloat(cultureInfo, defaultValue);
        }
        public static float GetFloat(string key, string cultureName)
        {
            return S1Cache.GetObject(key).ToFloat(cultureName);
        }
        public static float GetFloat(string key, string cultureName, float defaultValue)
        {
            return S1Cache.GetObject(key).ToFloat(cultureName, defaultValue);
        }
        public static double GetDouble(string key)
        {
            return S1Cache.GetObject(key).ToDouble();
        }
        public static double GetDouble(string key, double defaultValue)
        {
            return S1Cache.GetObject(key).ToDouble(defaultValue);
        }
        public static double GetDouble(string key, string cultureName)
        {
            return S1Cache.GetObject(key).ToDouble(cultureName);
        }
        public static double GetDouble(string key, string cultureName, double defaultValue)
        {
            return S1Cache.GetObject(key).ToDouble(cultureName, defaultValue);
        }
        public static double GetDouble(string key, CultureInfo cultureInfo)
        {
            return S1Cache.GetObject(key).ToDouble(cultureInfo);
        }
        public static double GetDouble(string key, CultureInfo cultureInfo, double defaultValue)
        {
            return S1Cache.GetObject(key).ToDouble(cultureInfo, defaultValue);
        }
        public static bool GetBoolean(string key)
        {
            return S1Cache.GetObject(key).ToBoolean();
        }
        public static bool GetBoolean(string key, bool defaultValue)
        {
            return S1Cache.GetObject(key).ToBoolean(defaultValue);
        }
        public static DateTime GetDateTime(string key)
        {
            return S1Cache.GetObject(key).ToDateTime();
        }
        public static DateTime GetDateTime(string key, DateTime defaultValue)
        {
            return S1Cache.GetObject(key).ToDateTime(defaultValue);
        }
        public static DateTime GetDateTime(string key, string cultureName)
        {
            return S1Cache.GetObject(key).ToDateTime(cultureName);
        }
        public static DateTime GetDateTime(string key, string cultureName, DateTime defaultValue)
        {
            return S1Cache.GetObject(key).ToDateTime(cultureName, defaultValue);
        }
        public static DateTime GetDateTime(string key, CultureInfo cultureInfo)
        {
            return S1Cache.GetObject(key).ToDateTime(cultureInfo);
        }
        public static DateTime GetDateTime(string key, CultureInfo cultureInfo, DateTime defaultValue)
        {
            return S1Cache.GetObject(key).ToDateTime(cultureInfo, defaultValue);
        }
        public static TimeSpan GetTimeSpan(string key)
        {
            return S1Cache.GetObject(key).ToTimeSpan();
        }
        public static TimeSpan GetTimeSpan(string key, TimeSpan defaultValue)
        {
            return S1Cache.GetObject(key).ToTimeSpan(defaultValue);
        }
    }
}
